<%@ page language="java"
		 contentType="text/html; charset=utf-8"
		 pageEncoding="utf-8" %>
<%@ page isELIgnored="false" %><!-- isELIgnored=true禁用EL表达式 -->

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!-- JSTL格式化标签 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
	<meta charset="UTF-8">
	<title>我的订单</title>
	<script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/index.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/indexstyle.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
	<meta name="viewport"
		  content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
</head>
<body>

<div class="site-nav-bg">
	<div class="site-nav w1200">
		<p class="sn-back-home">
			<i class="layui-icon layui-icon-home"></i>
			<a href="${pageContext.request.contextPath}/shop/shopPage">首页</a>
		</p>
		<div class="sn-quick-menu">
			<div class="sp-cart"><i class="layui-icon layui-icon-form"></i><a style="margin-left: 5px"><span style="color: red">我的订单</span></a></div>
			<div class="sp-cart" style="margin-left: 15px"><i class="layui-icon layui-icon-cart-simple"></i><a
					style="margin-left: 5px" href="${pageContext.request.contextPath}/car/carPage">购物车</a></div>
			<c:if test="${sessionScope.u.id != null}">
				<div style="margin-left: 10px">
					<a href="${pageContext.request.contextPath}/user/userPage">
						<div><i class="layui-icon layui-icon-user"></i>&nbsp;&nbsp;欢迎用户:<span>${sessionScope.u.uName}</span></div>
					</a>
				</div>
			</c:if>
			<c:if test="${sessionScope.u.id == null}">
				<div>
					<div class="login" style="margin-left: 15px"><i class="layui-icon layui-icon-user"></i><a
							style="margin-left: 5px" href="${pageContext.request.contextPath}/mall/login">登录</a></div>
				</div>
			</c:if>
		</div>
	</div>
</div>

<div class="content content-nav-base shopcart-content">


	<div class="main-nav">
		<div class="inner-cont0">
			<div class="inner-cont1 w1200">
				<div class="inner-cont2">
					<form class="layui-form" action="${pageContext.request.contextPath}/shop/goods/orderPage" method="post">
						<div class="layui-input-inline">
							<a class="active">订单查询</a>
						</div>
						<div class="layui-input-inline">
							<input type="text" name="gName"  id="categoryName" value="${order.gName}" class="layui-input" placeholder="请输入商品名称">
						</div>
						<div class="layui-input-inline">
							<select name="orderStatus">
								<option value="">订单状态</option>
								<option <c:if test="${order.orderStatus == 1}"> selected=true </c:if> value="1">待付款</option>
								<option <c:if test="${order.orderStatus == 2}"> selected=true </c:if> value="2">待发货</option>
								<option <c:if test="${order.orderStatus == 3}"> selected=true </c:if> value="3">已发货</option>
								<option <c:if test="${order.orderStatus == 4}"> selected=true </c:if> value="4">已签收</option>
								<option <c:if test="${order.orderStatus == 5}"> selected=true </c:if> value="5">退款中</option>
								<option <c:if test="${order.orderStatus == 6}"> selected=true </c:if> value="6">已退款</option>
								<option <c:if test="${order.orderStatus == 7}"> selected=true </c:if> value="7">交易结束</option>
							</select>
						</div>
						<div class="layui-input-inline">
							<button class="layui-btn layui-btn-sm layui-btn-primary" type="submit">
								<i class="layui-icon layui-icon-search"></i>
							</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<div class="cart w1200">
		<div class="cart-table-th">
			<div style="background-color: #fff1fa">
				<div class="order_root">
					<c:forEach items="${orderGoods}" var="orderGoods">
						<span class="order-title layui-font-20">订单号：${orderGoods.orderNo}</span>&nbsp;&nbsp;&nbsp;&nbsp;
						<span style="color: #f50808;font-size: 20px">状态：
							<c:if test="${orderGoods.orderStatus == 1}">待付款</c:if>
							<c:if test="${orderGoods.orderStatus == 2}">待发货</c:if>
							<c:if test="${orderGoods.orderStatus == 3}">已发货</c:if>
							<c:if test="${orderGoods.orderStatus == 4}">已签收</c:if>
							<c:if test="${orderGoods.orderStatus == 5}">退款中</c:if>
							<c:if test="${orderGoods.orderStatus == 6}">已退款</c:if>
							<c:if test="${orderGoods.orderStatus == 7}">交易结束</c:if>
						</span>&nbsp;&nbsp;&nbsp;&nbsp;
						<span>
							<c:if test="${orderGoods.orderStatus == 1}">
								<button class="layui-btn layui-btn-sm" onclick="openPayPass('${orderGoods.orderNo}')">支付</button>
								<button class="layui-btn layui-btn-sm layui-bg-gray" onclick="closePay('${orderGoods.orderNo}')">关闭交易</button>
							</c:if>
							<c:if test="${orderGoods.orderStatus == 2}">
								<button class="layui-btn layui-btn-sm" onclick="sign('${orderGoods.orderNo}')">签收</button>
								<button class="layui-btn layui-btn-sm layui-bg-gray" onclick="refund(${orderGoods.orderStatus},'${orderGoods.orderNo}')">申请退款</button>
							</c:if>
							<c:if test="${orderGoods.orderStatus == 3}">
								<button class="layui-btn layui-btn-sm" onclick="sign('${orderGoods.orderNo}')">签收</button>
								<button class="layui-btn layui-btn-sm layui-bg-gray" onclick="refund(${orderGoods.orderStatus},'${orderGoods.orderNo}')">申请退款</button>
							</c:if>
							<c:if test="${orderGoods.orderStatus == 4}">
								<button class="layui-btn layui-btn-sm layui-bg-gray" onclick="refund(${orderGoods.orderStatus},'${orderGoods.orderNo}')">申请退款</button>
							</c:if>
							<c:if test="${orderGoods.orderStatus == 5}">
								<button class="layui-btn layui-btn-sm layui-bg-gray" onclick="cancelRefund('${orderGoods.orderNo}')">取消退款</button>
							</c:if>
						</span>
						<div>
							<div class="layui-inline" style="margin-top: 1px;margin-left: 10px">
								<img src="${orderGoods.imgUrl}" style="height: 150px;">
							</div>
							<div class="layui-inline" style="height: 100px;">
								<span class="order-title layui-font-20">商品名称:${orderGoods.gName}</span>&nbsp;&nbsp;&nbsp;&nbsp;
								<span class="layui-font-20">下单时间：
									<f:formatDate value="${orderGoods.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
								</span>
								<div style="padding-top: 20px;">
									<span class="layui-font-20">单价：${orderGoods.gPrice}</span>-
									<span class="layui-font-20">购买数量：${orderGoods.buyCount}</span>
									<span class="layui-font-20">总价：${orderGoods.totalMoney}</span>
								</div>
							</div>
						</div>
						<hr style="background-color: #f50606;" />
					</c:forEach>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script>
	// 打开输入密码弹出层
	layui.use(['layer'], function () {
		var layer = layui.layer;
	});
	function openPayPass(orderNo){
		console.info(orderNo);
		layer.open({
			type: 2,
			area: ['350px', '200px'],
			title: "输入支付密码",
			content: '${pageContext.request.contextPath}/shop/goods/payPass?orderNo='+ orderNo,
			yes: function(index) {
				layer.close(index);
			},
		})
	}
	//关闭交易  将状态值改为7-交易关闭
	function closePay(orderNo){
		console.info(orderNo);
		$.ajax({
			url:"${pageContext.request.contextPath}/shop/goods/closePay",
			data:"orderNo="+orderNo,
			type:"post",
			success(code){
				if(code == "1"){
					alert("关闭交易成功");
				}else {
					alert("关闭交易失败");
				}
				window.location.reload();
			}
		});
	}
	//签收成功  将状态值改为4-已签收
	function sign(orderNo){
		console.info(orderNo);
		$.ajax({
			url:"${pageContext.request.contextPath}/shop/goods/sign",
			data:"orderNo="+orderNo,
			type:"post",
			success(code){
				if(code == "1"){
					alert("签收成功");
				}else {
					alert("签收失败");
				}
				window.location.reload();
			}
		});
	}
	//申请退款 将状态值改为5-退款中
	function refund(orderStatus,orderNo){
		console.info(orderNo);
		console.info(orderStatus);
		$.ajax({
			url:"${pageContext.request.contextPath}/shop/goods/refund",
			data:"orderNo="+orderNo+"&preStatus="+orderStatus,
			type:"post",
			success(code){
				if(code == "1"){
					alert("申请退款成功");
				}else {
					alert("申请退款失败");
				}
				window.location.reload();
			}
		});
	}
	//取消退款   显示原来退款钱的状态值
	function cancelRefund(orderNo){
		console.info(orderNo);
		$.ajax({
			url:"${pageContext.request.contextPath}/shop/goods/cancelRefund",
			data:"orderNo="+orderNo,
			type:"post",
			success(code){
				if(code == "1"){
					alert("取消退款成功");
				}else {
					alert("取消退款失败");
				}
				window.location.reload();
			}
		});
	}
</script>
</html>
